-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OrderedDictionary] forward ordered dictionary values equality to values property #335
[OrderedDictionary] forward ordered dictionary values equality to values property #335
Conversation
@swift-ci test |
@ingoem thanks for suggesting the reference equality check! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 👍
Tests/_CollectionsTestSupport/AssertionContexts/Assertions.swift
Outdated
Show resolved
Hide resolved
@vanvoorden Can you please rebase this PR on top of the I think it would make sense to ship this in the next patch release, rather than having it linger on main indefinitely. |
598b5f9
to
e42fb86
Compare
@lorentey Sounds good. Thanks! |
@lorentey Is there a CI job that can run |
Here are benchmarks running locally. The reason that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for rebasing. Nice work on the benchmarks! 👍
Reviewing #340 made me realize what's been bothering me about expectNotEqualElements
; I added new recommendations to remove it and the test that exercises it. (Please see the notes below.)
Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift
Outdated
Show resolved
Hide resolved
Sources/_CollectionsTestSupport/AssertionContexts/Assertions.swift
Outdated
Show resolved
Hide resolved
Tests/OrderedCollectionsTests/OrderedDictionary/OrderedDictionary+Values Tests.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
@lorentey Thanks for reviewing! |
@swift-ci test |
(AFAIK, CI runs are still expected to fail on macOS. This is "fine", and it won't block us from landing this.) |
…v1.0.6 (#822) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [com_github_apple_swift_collections](https://togithub.com/apple/swift-collections) | http_archive | patch | `1.0.5` -> `1.0.6` | --- ### Release Notes <details> <summary>apple/swift-collections (com_github_apple_swift_collections)</summary> ### [`v1.0.6`](https://togithub.com/apple/swift-collections/releases/tag/1.0.6): Swift Collections 1.0.6 [Compare Source](https://togithub.com/apple/swift-collections/compare/1.0.5...1.0.6) This bugfix release adds `Sendable` conformances to all public types (fixing compatibility with Swift's strict concurrency checking), and speeds up equality checks (`==`) of identical collection values. ##### What's Changed - Fix typos: OrderedSet Documentation by [@​kati-kms](https://togithub.com/kati-kms) in [https://github.com/apple/swift-collections/pull/322](https://togithub.com/apple/swift-collections/pull/322) - \[1.0] build: support building in Debug mode on Windows by [@​compnerd](https://togithub.com/compnerd) in [https://github.com/apple/swift-collections/pull/337](https://togithub.com/apple/swift-collections/pull/337) - build: tweak search path for embedding by [@​compnerd](https://togithub.com/compnerd) in [https://github.com/apple/swift-collections/pull/338](https://togithub.com/apple/swift-collections/pull/338) - \[OrderedDictionary] forward ordered dictionary values equality to values property by [@​vanvoorden](https://togithub.com/vanvoorden) in [https://github.com/apple/swift-collections/pull/335](https://togithub.com/apple/swift-collections/pull/335) - \[OrderedSet] forward ordered set equality to elements property by [@​vanvoorden](https://togithub.com/vanvoorden) in [https://github.com/apple/swift-collections/pull/340](https://togithub.com/apple/swift-collections/pull/340) - \[Deque] check deque equality with buffer identity by [@​vanvoorden](https://togithub.com/vanvoorden) in [https://github.com/apple/swift-collections/pull/341](https://togithub.com/apple/swift-collections/pull/341) - \[OrderedDictionary] Fix usage of deprecated API in index(forKey:) docs by [@​lorentey](https://togithub.com/lorentey) in [https://github.com/apple/swift-collections/pull/342](https://togithub.com/apple/swift-collections/pull/342) - \[1.0] Backport Sendable conformances on all public types by [@​lorentey](https://togithub.com/lorentey) in [https://github.com/apple/swift-collections/pull/343](https://togithub.com/apple/swift-collections/pull/343) - OrderedSet: Fix sendable conformance on old swifts by [@​lorentey](https://togithub.com/lorentey) in [https://github.com/apple/swift-collections/pull/346](https://togithub.com/apple/swift-collections/pull/346) - Update CMake configuration by [@​lorentey](https://togithub.com/lorentey) in [https://github.com/apple/swift-collections/pull/347](https://togithub.com/apple/swift-collections/pull/347) ##### New Contributors - [@​kati-kms](https://togithub.com/kati-kms) made their first contribution in [https://github.com/apple/swift-collections/pull/322](https://togithub.com/apple/swift-collections/pull/322) - [@​vanvoorden](https://togithub.com/vanvoorden) made their first contribution in [https://github.com/apple/swift-collections/pull/335](https://togithub.com/apple/swift-collections/pull/335) **Full Changelog**: apple/swift-collections@1.0.5...1.0.6 Thank you to everyone who contributed to this release! </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
Background
#334
The current implementation of
OrderedDictionary.Values.==
forwards toSequence.elementsEqual
, which needs to perform a linear-time (O[N]
) comparison over both collections.[1]Since the "backing store" of our
OrderedDictionary.Values
is aContiguousArray
, we can forward that equality check through toContiguousArray
. If bothValues
instances point to the same identity, theContiguousArray
implementation will return early from the comparison.[2]We perform a similar check (against the
ContiguousArray
) in our implementation ofOrderedDictionary.==
.[3][1] https://github.com/apple/swift/blob/main/stdlib/public/core/SequenceAlgorithms.swift#L319-L336
[2] https://github.com/apple/swift/blob/main/stdlib/public/core/ContiguousArray.swift#L1318-L1321
[3] https://github.com/apple/swift-collections/blob/main/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary%2BEquatable.swift#L20-L22
Changes
We migrate from:
We migrate to:
Test Plan
Two new tests are added:
OrderedDictionaryValueTests.test_values_getter_equal
OrderedDictionaryValueTests.test_values_getter_not_equal
Checklist